<?php
    use User\Model\MeetingModel;
?>
<!-- page heading start-->
<div class="page-heading">
    <h3>
        会员详情
    </h3>

</div>
<link rel="stylesheet" href="/Public/projects/meeting/css/ydui.css"/>
<script type="text/javascript" src="/Public/js/laydatenew/laydate.js"></script>
<!-- page heading end-->
<div class="row">
    <div class="col-sm-12">
        <section class="panel">
            <div class="panel-body">
                    <form method="post" action="/User/Meeting/registerUpdate" enctype="multipart/form-data">
                        <input type="hidden" name="meetId" value="<?php echo I('get.meetId', '', '');?>">
                        <input type="hidden" name="userId" value="<?php echo I('get.userId', '', '');?>">
                        <?php
                    foreach($fields as $field){
                        if($field['type'] == MeetingModel::FIELD_TEXT){
                            echo '<div style="width:400px;">' . $field['name'] . ':<input type="text" class="form-control" name="' . $field['field_id'] .'" value="';
                            if(isset($display_field[$field['field_id']])){
                                echo $display_field[$field['field_id']];
                            }
                            echo '"></div>';
                            }
                            if($field['type'] == MeetingModel::FIELD_TEXTAREA){
                                echo '<div  style="width:400px;">' . $field['name'] . ':<textarea class="form-control" name="' . $field['field_id'] .'">';
                                if(isset($display_field[$field['field_id']])){
                                    echo $display_field[$field['field_id']];
                                }
                                echo '</textarea></div>';
                            }
                            if($field['type'] == MeetingModel::FIELD_SINGLE){
                                echo '<div><div>' . $field['name'] . ":</div>";
                                if($field['option']){
                                    $options = json_decode($field['option'], true);
                                    foreach($options as $option){
                                        echo '<input type="radio" name="' . $field['field_id'] . '" value="' . $option . '"';
                                        if(isset($display_field[$field['field_id']]) && $display_field[$field['field_id']] == $option){
                                            echo ' checked ';
                                        }
                                        echo '>' . $option;
                                    }
                                }
                                echo '</div>';
                            }
                            if($field['type'] == MeetingModel::FIELD_MULTIPLE){
                                echo '<div><div>' . $field['name'] . ":</div>";
                                if($field['option']){
                                    $options = json_decode($field['option'], true);
                                    $checked_options = array();
                                    if(!empty($display_field[$field['field_id']])){
                                        $checked_options = json_decode($display_field[$field['field_id']], true);
                                    }
                                    foreach($options as $k => $option){
                                        echo '<input type="checkbox" name="' . $field['field_id'] . '[]" value="' . $option . '"';
                                        if(is_array($checked_options) && in_array($option, $checked_options)){
                                            echo " checked ";
                                        }
                                        if(!is_array($checked_options) && ($option === $checked_options)){
                                            echo " checked ";
                                        }
                                        echo '>' . $option;
                                    }
                                }
                                echo '</div>';
                            }
                            if($field['type'] == MeetingModel::FIELD_PIC){
                                echo '<div><div>' . $field['name'] . ":</div>";
                                echo '<img src="';
                            if(isset($display_field[$field['field_id']])){
                                echo $display_field[$field['field_id']];
                            }
                            echo '" alt="" style="width: 200px;height: 200px;"><input name="' . $field['field_id'] . '" value="';
                            if(isset($display_field[$field['field_id']])){
                                echo $display_field[$field['field_id']];
                            }
                            echo '" type="file" onchange="readFile(this);">';
                                if(isset($display_field[$field['field_id']])){
                                    echo "<input type='hidden' value='" . $display_field[$field['field_id']] . "' name='";
                                    echo $field['field_id'];
                                    echo "' >";
                                }
                                echo '</div>';
                            }
                            if($field['type'] == MeetingModel::FIELD_CITY){
                                echo '<div><div>' . $field['name'] . ":</div>";
                                echo '<input class="form-control J_Address" style="width: 400px;" placeholder="请输入所在地区" value="';
                            if(isset($display_field[$field['field_id']])){
                                echo $display_field[$field['field_id']];
                            }
                            echo '" readonly>';
                                echo '<input type="hidden" class="province" name="province' . $display_field[$field['field_id']] . '" value="';
                            if(isset($display_field[$field['field_id']])){
                                $data_city = explode(',', $display_field[$field['field_id']]);
                                echo $data_city[0];
                            }
                            echo '">';
                                echo '<input type="hidden" class="city" name="city' . $display_field[$field['field_id']] . '" value="';
                            if(isset($display_field[$field['field_id']])){
                                $data_city = explode(',', $display_field[$field['field_id']]);
                                echo $data_city[1];
                            }
                            echo '">';
                                echo '<input type="hidden" class="district" name="district' . $display_field[$field['field_id']] . '" value="';
                            if(isset($display_field[$field['field_id']])){
                                $data_city = explode(',', $display_field[$field['field_id']]);
                                echo $data_city[2];
                            }
                            echo '"></div>';
                            }
                            if($field['type'] == MeetingModel::FIELD_ADDRESS){
                                echo '<div><div>' . $field['name'] . ":</div>";
                                echo '<input class="form-control J_Address" style="width: 400px;" placeholder="请输入所在地区" value="';
                            if(isset($display_field[$field['field_id']])){
                                echo $display_field[$field['field_id']];
                            }
                            echo '" readonly>';
                                echo '<input type="hidden" class="province" name="province' . $display_field[$field['field_id']] . '" value="';
                            if(isset($display_field[$field['field_id']])){
                                $data_city = explode(',', $display_field[$field['field_id']]);
                                echo $data_city[0];
                            }
                            echo '">';
                                echo '<input type="hidden" class="city" name="city' . $display_field[$field['field_id']] . '" value="';
                            if(isset($display_field[$field['field_id']])){
                                $data_city = explode(',', $display_field[$field['field_id']]);
                                echo $data_city[1];
                            }
                            echo '">';
                                echo '<input type="hidden" class="district" name="district' . $display_field[$field['field_id']] . '" value="';
                            if(isset($display_field[$field['field_id']])){
                                $data_city = explode(',', $display_field[$field['field_id']]);
                                echo $data_city[2];
                            }
                            echo '">';
                                echo '<textarea class="form-control" style="width:400px;margin-top: 10px;" name="address' . $display_field[$field['field_id']] . '">';
                                if(isset($display_field[$field['field_id']])){
                                $data_city = explode(',', $display_field[$field['field_id']]);
                                    echo $data_city[3];
                                }
                                echo '</textarea></div>';
                            }
                            if($field['type'] == MeetingModel::FIELD_DATE){
                                echo '<div><div>' . $field['name'] . ":</div>";
                                echo '<input class="form-control" id="#date' . $field['field_id'] . '" style="width: 200px;" name="' . $field['field_id'] . '" value="';
                            if(isset($display_field[$field['field_id']])){
                                echo $display_field[$field['field_id']];
                            }
                            echo '"></div>';
                                echo '<script>laydate.render({
                                    elem: "#date' . $field['field_id'] . '"
                                });</script>';
                            }
                            if($field['type'] == MeetingModel::FIELD_TIME){
                                echo '<div><div>' . $field['name'] . ":</div>";
                                echo '<input class="form-control" id="time' . $field['field_id'] . '" style="width: 200px;" name="' . $field['field_id'] . '" value="';
                            if(isset($display_field[$field['field_id']])){
                                echo $display_field[$field['field_id']];
                            }
                            echo '"></div>';
                                echo '<script>laydate.render({
                                    elem: "#time' . $field['field_id'] . '",
                                    type: "datetime"
                                });</script>';
                            }
                            if($field['type'] == MeetingModel::FIELD_RANGE){
                                echo '<div><div>' . $field['name'] . ":</div>";
                                $date_range = $display_field[$field['field_id']];
                                $date_arr = array();
                                if(!empty($date_range)){
                                    $date_arr = explode('-', $date_range);
                                }
                                echo '<input class="form-control" id="start' . $field['field_id'] . '" style="width: 200px;float: left" name="start' . $field['field_id'] . '"';
                                if(!empty($date_arr[0])){
                                    echo " value='" . $date_arr[0] . "' ";
                                }
                                echo ' ><span style="float: left">-</span>';
                                echo '<input class="form-control" id="end' . $field['field_id'] . '" style="width: 200px;" name="end' . $field['field_id'] . '" ';
                                if(!empty($date_arr[1])){
                                    echo " value='" . $date_arr[1] . "' ";
                                }
                                echo ' ></div>';
                                echo '<script>laydate.render({
                                    elem: "#start' . $field['field_id'] . '"
                                });laydate.render({
                                    elem: "#end' . $field['field_id'] . '"
                                });</script>';
                            }
                        }?>
                        <?php if($meet && !empty($meet['hotel_service'])){?>
                        <div style="width: 400px;">
                            <div>是否住宿：<input type="radio" value="0" name="is_hotel" <?php if(empty($user) || empty($user['is_hotel'])){ echo 'checked';}?>>否
                                <input type="radio" value="1" name="is_hotel"  <?php if(!empty($user) && !empty($user['is_hotel'])){ echo 'checked';}?>>是</div>
                            <div>住宿人数：<input type="text" value="<?php echo $user['hotel_person']?>" name="hotel_person" class="form-control"></div>
                            <div>住宿备注：<textarea name="hotel_note" class="form-control"><?php echo $user['hotel_note']?></textarea></div>
                        </div>
                        <?php }if($meet && !empty($meet['eat_service'])){?>
                        <div style="width: 400px;">
                            <div>是否就餐：<input type="radio" value="0" name="is_eat" <?php if(empty($user) || empty($user['is_eat'])){ echo 'checked';}?>>否
                                <input type="radio" value="1" name="is_eat"  <?php if(!empty($user) && !empty($user['is_eat'])){ echo 'checked';}?>>是</div>
                            <div>就餐人数：<input type="text" value="<?php echo $user['eat_person']?>" name="eat_person" class="form-control"></div>
                            <div>就餐备注：<textarea name="eat_note" class="form-control"><?php echo $user['eat_note']?></textarea></div>
                        </div>
                        <?php }if($meet && !empty($meet['bus_service'])){?>
                        <div style="width: 400px;">
                            <div>是否乘车：<input type="radio" value="0" name="is_bus" <?php if(empty($user) || empty($user['is_bus'])){ echo 'checked';}?>>否
                                <input type="radio" value="1" name="is_bus"  <?php if(!empty($user) && !empty($user['is_bus'])){ echo 'checked';}?>>是</div>
                            <div>乘车人数：<input type="text" value="<?php echo $user['bus_person']?>" name="bus_person" class="form-control"></div>
                            <div>乘车备注：<textarea name="bus_note" class="form-control"><?php echo $user['bus_note']?></textarea></div>
                        </div>
                        <?php } ?>
                        <div style="width: 400px;">
                            <div>状态：</div>
                            <select name="status" class="form-control">
                                <option value="0" <?php if(empty($user) || empty($user['status'])){ echo 'selected';}?>>待审核</option>
                                <option value="1" <?php if(!empty($user) && !empty($user['status']) && ($user['status'] == 1)){ echo 'selected';}?>>正常</option>
                                <option value="2" <?php if(!empty($user) && !empty($user['status']) && ($user['status'] == 2)){ echo 'selected';}?>>未通过审核</option>
                                <option value="3" <?php if(!empty($user) && !empty($user['status']) && ($user['status'] == 3)){ echo 'selected';}?>>已使用</option>
                            </select>
                        </div>
                        <div style="width:400px;" id="result">未通过原因：<input type="text" class="form-control" name="result" value="{$user['result']}"></div>
                        <div style="margin-top: 40px;">
                            <button type="submit" class="btn btn-primary" >提交更改</button>
                            <button type="button" class="btn btn-default" onclick="history.back(-1);" style="margin-left: 30px;">返回</button>
                        </div>
                    </form>
                </div>
        </section>
    </div>
</div>
<script>
    var img_tag = '';
    function readFile(img) {
        img_tag = $(img);
        var file = img.files[0];
        if (!/image\/\w+/.test(file.type)) {
            alert("请确保文件为图像类型");
            return false;
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {
            img_tag.prev().attr("src", this.result);
        }
    }
    if($("select[name=status]").val() == 2){
        $("#result").css("display", "block");
    }else{
        $("#result").css("display", "none");
    }
    $("select[name=status]").change(function(){
        if($(this).val() == 2){
            $("#result").css("display", "block");
        }else{
            $("#result").css("display", "none");
        }
    })
</script>
<script type="text/javascript" src="/Public/projects/meeting/js/ydui.citys.js"></script>
<script type="text/javascript" src="/Public/projects/meeting/js/ydui.js"></script>
<script type="text/javascript">
    !function () {
        $(".J_Address").each(function(){
            var $target = $(this);
            var province = $target.nextAll(".province").val();
            var city = $target.nextAll(".city").val();
            var district = $target.nextAll(".district").val();
            $target.citySelect({
                provance: province,
                city:city,
                area:district
            });

            $target.on('click', function (event) {
                event.stopPropagation();
                $target.citySelect('open');
            });

            $target.on('done.ydui.cityselect', function (ret) {
                $(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
                $(this).nextAll(".province").val(ret.provance);
                $(this).nextAll(".city").val(ret.city);
                $(this).nextAll(".district").val(ret.area);
            });
        });
    }();
</script>
